local ty_jiangling = fk.CreateSkill {
  name = "ty_jiangling",
  mode_skill = true,
}

Fk:loadTranslationTable{
  ["ty_jiangling"] = "江陵",
  [":ty_jiangling"] = "出牌阶段开始时，您可以选择一项：1.此阶段你使用【杀】和普通锦囊牌无次数限制；2.此阶段你使用【杀】和普通锦囊牌可以增加一个目标。",

  ["ty_jiangling_1"] = "无次数限制",
  ["ty_jiangling_2"] = "增加一个目标",
  ["#ty_jiangling-ask"] = "江陵：你可令你此阶段使用【杀】和普通锦囊牌获得一项效果",
  ["#ty_jiangling-add"] = "江陵：你可以为此%arg增加一个目标",
}

ty_jiangling:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(ty_jiangling.name) and player.phase == player.Play
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = room:askToChoice(
      player,
      {
        choices = { "ty_jiangling_1", "ty_jiangling_2" },
        skill_name = ty_jiangling.name,
        prompt = "#ty_jiangling-ask",
      }
    )
    room:setPlayerMark(player, "ty_jiangling-phase", choice)
  end,
})

ty_jiangling:addEffect(fk.AfterCardTargetDeclared, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("ty_jiangling-phase") == "ty_jiangling_2" and
    (data.card.trueName == "slash" or data.card:isCommonTrick()) and #data:getExtraTargets() > 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local tos = room:askToChoosePlayers(player, {
      targets = data:getExtraTargets(),
      min_num = 1,
      max_num = 1,
      prompt = "#ty_jiangling-add:::"..data.card:toLogString(),
      skill_name = ty_jiangling.name,
      cancelable = true,
    })
    if #tos > 0 then
      event:setCostData(self, {tos = tos})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local to = event:getCostData(self).tos[1]
    player.room:sendLog{
      type = "#AddTargetsBySkill",
      from = player.id,
      to = {to.id},
      arg = ty_jiangling.name,
      arg2 = data.card:toLogString()
    }
    data:addTarget(to)
  end,
})

ty_jiangling:addEffect("targetmod", {
  bypass_times = function(self, player, skill, scope, card, to)
    return card and (card.trueName == "slash" or card:isCommonTrick()) and player:getMark("ty_jiangling-phase") == "ty_jiangling_1"
  end,
})

return ty_jiangling